import React from 'react'
import {Routes, Route, Navigate, BrowserRouter} from "react-router";
import {ConfigProvider} from "antd";
import zhCN from 'antd/locale/zh_CN';
import { Provider } from 'react-redux'
import store from './redux/store.js';
import {loadUserLocalStorage}  from "./redux/localStorage.js";

const Login = React.lazy(() => import('./pages/Login.jsx'));
const Register = React.lazy(() => import('./pages/Register.jsx'));
const ForgetPassword = React.lazy(() => import('./pages/ForgetPassword.jsx'));

const initialUserData = loadUserLocalStorage();
store.dispatch({
    type: 'SET_USER_DATA',
    payload: initialUserData
})

function App(){
    return (
        <Provider store={store}>
            <ConfigProvider
                theme={{
                    token:{
                        colorPrimary:'#1890ff',
                        borderRadius: 2,
                    }
                }}
                locale={zhCN}
            >
                <BrowserRouter>
                    <Routes>
                        <Route path="/" element={<Navigate to="/login" />} />
                        <Route path="/login" element={<Login />} />
                        <Route path="/register" element={<Register />} />
                        <Route path="/forgetpassword" element={<ForgetPassword />} />
                    </Routes>
                </BrowserRouter>
            </ConfigProvider>
        </Provider>
    );
}

export default App;